<template>
  <div class="l-rblock l-form-viewer" style="padding: 8px">
    <el-row :gutter="16">
      <div class="l-rblock">
        <el-col :span="24">
          <div class="font_size_24 form_flex_center" v-if="type != 0">
            {{ $t("供应商年审") }}
          </div>
          <div class="font_size_24 form_flex_center" v-if="type == 0">
            {{ $t("供应商评估报告") }}
          </div>

          <div class="form_name">{{ $t("基本信息") }}</div>

          <div class="form_back form_flex mt-16">
            <div>
              {{ $t("供应商编号：" + formData.case_erp_supplier_f_Number) }}
            </div>
            <div>
              {{ $t("供应商名称：" + formData.case_erp_supplier_f_Name) }}
            </div>
            <div>
              {{ $t("供应商负责人：" + formData.case_erp_supplier_f_Person) }}
            </div>
            <div>
              {{ $t("供应商类型：" + formData.case_erp_supplier_f_Type) }}
            </div>
            <div>
              {{ $t("添加人：" + formData.case_erp_supplier_f_CreateUserName) }}
            </div>
            <div>
              {{ $t("创建日期：" + formData.case_erp_supplier_f_CreateDate) }}
            </div>
            <div>
              {{ $t("经营范围：" + formData.case_erp_supplier_f_Scope) }}
            </div>
            <div>
              {{ $t("手机号：" + formData.case_erp_supplier_f_Phone) }}
            </div>
          </div>
        </el-col>
        <div style="padding: 0 8px">
          <assess-form
            class="mb-8"
            ref="assessForm"
            :isReadOnly="isReadOnly"
            :id="id"
            :type="type"
          />
          <el-col :span="24">
            <div class="mt-8 mb-8 text-center" v-if="!isReadOnly">
              <el-button
                size="mini"
                type="primary"
                class="btn_width200_height40"
                @click="saveForm"
                v-loading.fullscreen.lock="fullscreenLoading"
                >{{ $t("保存提交") }}</el-button
              >
            </div>
          </el-col>
        </div>
      </div>
    </el-row>
  </div>
</template>
<script>
import AssessForm from "./assessForm";
const api = window.$api.erpcase.supplier;
export default {
  components: {
    AssessForm,
  },
  props: {
    isReadOnly: {
      type: Boolean,
      default: false,
    },
    id: {},
    type: {},
  },
  data() {
    return {
      fullscreenLoading: false,
      moduleCode: "ERP_Suppliers",
      formData: {
        case_erp_supplier_f_Number: "", // 供应商编号
        case_erp_supplier_f_Name: "", // 供应商名称
        case_erp_supplier_f_Person: "", // 供应商负责人
        case_erp_supplier_f_Type: "", // 供应商类型
        case_erp_supplier_f_CreateUserName: "", // 添加人
        case_erp_supplier_f_CreateDate: "", // 创建日期
        case_erp_supplier_f_Scope: "", // 经营范围
        case_erp_supplier_f_Phone: "", // 手机号
      },
    };
  },
  computed: {},
  created() {
    this.loadFormData({ keyValue: this.id });
  },
  methods: {
    // 重置表单
    resetForm() {
      this.$refs.assessForm.resetForm && this.$refs.assessForm.resetForm();
    },
    // 校验表单
    validateForm() {
      return this.$refs.assessForm.validateForm();
    },
    // 设置表单数据
    setForm(data) {
      this.$setFormData(this.formData, data, "case_erp_supplier");
      this.formData.case_erp_supplier_f_CreateDate = this.$formatDate(
        this.formData.case_erp_supplier_f_CreateDate,
        "yyyy-MM-dd"
      );
    },
    async loadFormData({ keyValue /*,params,node*/ }) {
      const data = await this.$awaitWraper(api.get(keyValue));
      if (data) {
        this.setForm(data);
      }
    },
    async saveForm() {
      this.fullscreenLoading = true;
      if (await this.validateForm()) {
        const postData = this.$refs.assessForm.getForm();
        const res = await this.$awaitWraper(api.addAssess(postData));
        if (res) {
          this.$message({
            type: "success",
            message: this.$t("评估成功!"),
          });
          this.$emit("submit");
        }
      }
      this.fullscreenLoading = false;
    },
  },
};
</script>